package controllers

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func Output(c *gin.Context) {
	flag := c.Query("flag")
	if flag == "json" {
		outputJson(c)
	} else if flag == "xml" {
		outputXML(c)
	} else if flag == "yaml" {
		outputYAML(c)
	}
}

// 输出json
func outputJson(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "success",
	})
}

// 输出XML
func outputXML(c *gin.Context) {
	type Message struct {
		Code    int
		Message string
	}
	info := Message{}
	info.Code = 200
	info.Message = "Success"
	c.XML(http.StatusOK, info)
}

// 输出YAML
func outputYAML(c *gin.Context) {
	c.YAML(http.StatusOK, gin.H{
		"code":    200,
		"message": "输出YAML内容",
	})
}
